package com.jtny.nytb.equipment.dao.rule;

import com.jtny.component.core.mapper.CoreMapper;
import com.jtny.nytb.equipment.domain.rule.MeterCodeRulePreconditionDO;
import com.jtny.nytb.equipment.vo.rule.CodeRuleDictQueryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 智慧能源中心 - 伍天宇
 * @package com.jtny.energymonitor.equipment.dao
 * @fileName MeterCodeRulePreconditionDAO.java
 * @createTime 2023年10月08日 09:36
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Mapper
public interface MeterCodeRulePreconditionDAO extends CoreMapper<MeterCodeRulePreconditionDO> {
    /**
     * 按目标级别 ID 列出规则 ID
     *
     * @param targetLevelId 目标级别 ID
     * @return {@link List}<{@link Long}>
     */
    @Select("SELECT DISTINCT rule_id FROM em_equipment_meter_code_rule_precondition " +
            "WHERE target_level_id = #{targetLevelId}")
    List<Long> listRuleIdByTargetLevelId(@Param("targetLevelId") Long targetLevelId);

    /**
     * 按目标级别 ID 列出规则 ID
     *
     * @param targetLevelId 目标级别 ID
     * @return {@link List}<{@link Long}>
     */
    @Select("SELECT DISTINCT rule_id FROM em_equipment_meter_code_rule_precondition " +
            "WHERE target_level_id = #{targetLevelId} and rule_dict_ids = ''")
    List<Long> listRuleIdByTargetLevelIdAndDictIds(@Param("targetLevelId") Long targetLevelId);

    /**
     * 按目标级别 ID 和字典查询列出规则 ID
     *
     * @param targetLevelId     目标级别 ID
     * @param codeRuleDictQuery 代码规则字典查询
     * @return {@link List}<{@link Long}>
     */
    @Select("SELECT DISTINCT rule_id FROM em_equipment_meter_code_rule_precondition " +
            "WHERE target_level_id = #{targetLevelId} " +
            "AND rule_level_id = #{codeRuleDictQuery.levelId} AND rule_dict_ids like '%,${codeRuleDictQuery.dictId},%'")
    List<Long> listRuleIdByTargetLevelIdAndDictQuery(@Param("targetLevelId") Long targetLevelId,
                                                     @Param("codeRuleDictQuery") CodeRuleDictQueryVO codeRuleDictQuery);
}
